
<form class="days" name="formDays" action="" method="POST" enctype="multipart/form-data">

    <img src="/resource/www/imgs/huod_2.png" class="jind-img">

    <div class="li fix">
        <span class="text">活动名称</span>
        <input type="text" name="name" value="<{$activity.name}>" class="route-name" placeholder="例如：法国巴黎豪华三日游，20个字以内" maxlength="20">
    </div>

    <div class="li fix">
        <span class="text">活动介绍</span>
        <textarea class="lux-miaos" name="summary" placeholder="有什么特色？吸引人的地方？有趣的背景故事？"><{$activity.summary}></textarea>
    </div>

    <div class="li fix">
        <span class="text">行程安排</span>
        <textarea class="lux-miaos" name="todolist" placeholder="例如：第一天游玩巴黎铁塔"><{$activity.todolist}></textarea>
    </div>

    <div class="li fix">
        <span class="text jingd">活动横幅图</span>
        <div class="upload banner" style="background-size: cover;<{if $activity.bannerUrl}>background-image:url(<{$activity.bannerUrl}>);<{/if}> ">
            <input type="file" name="bannerUrl">
        </div>
        <span>
    </div>


    <div class="li fix">
        <span class="text jingd">活动缩略图</span>
        <div class="upload thumb" style="background-size: cover;<{if $activity.thumb}>background-image:url(<{$activity.thumb}>);<{/if}> ">
            <input type="file" name="thumb">
        </div>
        <span>
    </div>


    <div class="li fix">
        <span class="text">活动图片</span>
        <div class="imgbox">
            <ul class="box fix" style="width:700px;">
               <{foreach from=$activity.images item="img"}>
                <li class="imgli" style="background-size: cover;background-image:url('<{$img}>');">
                <input type="file" class="file active hasImgLastTime" name="images[]">
                <input type="hidden" name="ImgsLastTime[]" value="<{$img}>">
                <div class="cancel-btn" style="background: url(/resource/www/imgs/upload_icon_delete.png) no-repeat;background-size:20px 20px;
                position: absolute;width: 20px;height: 20px;top: -10px;left: 150px;z-index: 99;">
                </div>
                </li>
               <{/foreach}> 
                <li class="imgli" style="background-size: cover;"><input type="file" class="file" name="images[]"></li>
                
            </ul>
        </div>
    </div>

    <div class="li fix">
        <span class="text">活动时长</span>
        <input type="text" name="hours" value="<{$activity.hours}>" id="" class="shic">
        <span class="shij">小时</span>
    </div>


    <div class="click-btn fix">
        <a href="javascript:;" onclick="javascript :history.back(-1);" class="go-back">上一步</a>
        <input type="submit" name="submit1" class="submit" value="下一步" onclick="return submit_artiv_days();">
    </div>

</form>

<script>

$("input[name=thumb]").change(event_upload_change);
$("input[name=bannerUrl]").change(event_upload_change);
$(".imgbox ul.box").delegate("input","change",function(event){
	//判断是否是第一次上传
	if(!$(this).hasClass("active")){
		$(this).addClass("active");
		var cancel="<div class='cancel-btn' style='background: url(/resource/www/imgs/upload_icon_delete.png) no-repeat;background-size:20px 20px;position: absolute;width: 20px;height: 20px;top: -10px;left: 150px;z-index: 99;'></div>"
		$(this).parent().append(cancel);
		var html="<li class='imgli' style='background-size: cover;'><input type='file' class='file' name='images[]'></li>";
		$(this).parent().parent().append(html);
	}
	//清空上次上传的图片
	if($(this).hasClass("hasImgLastTime")){
		$(this).removeClass("hasImgLastTime");
		$(this).parent().find('input:hidden').val('');
	}
	
	event_upload_change(event);
});
//删除按钮
$(".imgbox ul.box").delegate(".cancel-btn","click",function(){
	$(this).parent().remove();
});

function event_upload_change (event) {
        var file = $(event.target)[0].files[0];
        if(file){
        	var src = URL.createObjectURL(file);
            $(event.target).parent().css("background-image","url("+src+")");
        }        
        return;
}
</script>

<script>

function submit_artiv_days() {

    var oName = $('.days').find("input[name='name']").val();
    if (!$.trim(oName)) {
        layer.msg('请输入活动名称');
        return false;
    }

    var oSummary = $('.days').find("textarea[name='summary']").val();
    if (!$.trim(oSummary)) {
        layer.msg('请输入活动介绍');
        return false;
    }

    var oTodolist = $('.days').find("textarea[name='todolist']").val();
    if (!$.trim(oTodolist)) {
        layer.msg('请输入行程安排');
        return false;
    }

    if ($('input:file[name="bannerUrl"]').parent().css('backgroundImage').indexOf('up_img_icon') > -1 ) {
         layer.msg('请选择活动横幅图');
         return false;
    }

     if ($('input:file[name="thumb"]').parent().css('backgroundImage').indexOf('up_img_icon') > -1 ) {
         layer.msg('请选择活动缩略图');
         return false;
    }


    var oFile = 1;
    $("input[name*='images']").parent().each(function(){
        if( $(this).css('backgroundImage').indexOf('up_img2') == -1 ) {
            oFile = 0;
        }
    });
    if (oFile) {
        layer.msg('请选择活动图片');
        return false;
    }

    var oHours = $('.days').find("input[name='hours']").val();
    var oNumberReg =  /^[0-9]*[1-9][0-9]*$/;
    if (!$.trim(oHours) || !oNumberReg.test($.trim(oHours)) ) {
        layer.msg('请输入活动时长');
        return false;
    }
    
    layer.msg("资料上传中，请耐心等待 ...", {shade: [0.7, '#1a1a1a'], time: 600000 });
    window.setTimeout(function () {
        $('form[name=formDays]').submit();
    }, 200);

    return false;

}

</script>
